<?php
namespace Api\Controller;
use Common\Controller\AppframeController;
class UserController extends AppframeController {


	function _initialize() {
	}
	
	function index(){			
		$this->display();
	}
	//登陆接口
	function dologin(){
		$user_name = I('post.user_name'); 
		$user_pass = I('post.user_pass');		
		$token = $this->settoken();
		
		$users_model = M('Users');
		$userinfo = $users_model->where(array('user_login'=>$user_name))->find();
			if($userinfo){
				if(sp_compare_password($user_pass,$userinfo['user_pass'])){     //自带密码比对函数，666;
					$users_model->where(array('user_login'=>$user_name))->setField('token',$token);
					$logininfo['token'] = $token;
					$logininfo['status'] = 1;
					$logininfo['user_name'] = $user_name;					
					$this->ajaxReturn($logininfo);			
				}else{
					$logininfo['status'] = 0;
					$this->ajaxReturn($logininfo);
				}
			}else{
				$logininfo['status'] = -1;
				$this->ajaxReturn($logininfo);
			}
	}
	
	private function settoken() {
        $str = md5(microtime(true));  //生成一个不会重复的字符串
        //$str = sha1($str);  //加密
        return $str;
		//echo($str);
    }
	
	private function test(){
		$pass = "123abc";
		$passnew = "###".$pass;			
	}
	
}